<template>
  <div class="wrap backgroundAuto" :style="{ backgroundImage: `url('${ backgroundImage }')` }">
    <div class="btn-box">
      <div class="btn" @click="initVuex">initVuex</div>
      <div class="btn" @click="logVuex">logVuex</div>
    </div>
    <div class="btn-box">
      <div class="btn" @click="setToken">setToken</div>
      <div class="btn" @click="logToken">logToken</div>
    </div>
    <div class="btn-box">
      <div class="btn" @click="getRequest">get</div>
      <div class="btn" @click="postRequest">post</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onActivated } from "vue"
import {storeCommit, storeState} from "@/store/tools"
import { getReq, postReq } from "@/axios/request"
import backgroundImage from "@/assets/vuex.svg"

console.log('首次进入')
onActivated(() => {
  console.log('缓存页面')
})

function logToken() {
  console.log(storeState.token)
}
function setToken() {
  storeCommit('setToken', 'token改变了')
}
function logVuex() {
  console.log(storeState)
}
function initVuex() {
  storeCommit('init')
}
function getRequest() {
  console.log("const res = await getReq('url', { 可选，请求参数 })")
}
function postRequest() {
  console.log("const res = await postReq('url', { 可选，请求参数 })")
}
</script>

<style scoped lang="less">
.wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.btn-box {
  width: 200px;
  height: 40px;
  display: flex;
  justify-content: space-between;
  .btn {
    width: 45%;
    height: 40px;
    color: #ffd700;
    text-align: center;
    font-size: 20px;
    line-height: 40px;
    border-radius: 4px;
    border: solid 0.5px rgba(0, 0, 0, 0);
    transition: 0.2s;
  }
  .btn:active {
    border-color: #b0c4de;
    color: #b0c4de;
  }
}
</style>
